home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: April 22, 1998
- //<doc>
- //<name findAllIntersections>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<keywords>
- // curve NURBS intersect
- //
- //<synopsis>
- // string[] findAllIntersections(string $crvs[], int $numCrvsToIntersect,
- // int $useDir, float $dirX, float $dirY, float $dirZ,
- // float $tolerance, int $sorted, int $history,
- // string $intersectNodes[] )
- //
- //<description>
- // Find all intersections between a list of curves, two at a time.
- // If there are no intersections, then no nodes are created.
- //
- //<flags>
- // string[] $crvs List of curves to intersect
- // int $crvCount Number of curves on the list
- // int $useDir Use the direction for intersection
- // float $dirX X Direction for intersection
- // float $dirY Y Direction for intersection
- // float $dirZ Z Direction for intersection
- // float $tolerance Intersection tolerance
- // int $sorted Sort the parameter list?
- // int $history Remember construction history?
- // string[] $intersectNodes List of intersection nodes created
- //
- //<returns>
- // void :
- //
- //</doc>
-
- // Description:
- // This proc creates a crv-crv intersection node with two curves
- // and returns the name of the new crv-intersect DN. Also returns
- // the parameters at which the curves intersect each other.
- // If there are no intersections, then no node is created and
- // nothing is returned.
- //
- proc string createCrvCrvIntersect( string $crv1, string $crv2,
- int $useDir, float $dirX, float $dirY, float $dirZ,
- float $tolerance,
- float $intersections1[], float $intersections2[] )
- {
- // Create the intersect node
- //
- string $intersectNode = `createNode curveIntersect`;
- setAttr ($intersectNode + ".tolerance") $tolerance;
- connectAttr ($crv1 + ".worldSpace") ($intersectNode + ".inputCurve1");
- connectAttr ($crv2 + ".worldSpace") ($intersectNode + ".inputCurve2");
-
- setAttr ($intersectNode + ".useDirection") $useDir;
- setAttr ($intersectNode + ".direction") -type "double3" $dirX $dirY $dirZ;
-
- // Check if there are any intersections. If not, then delete
- // the node and return nothing.
- //
- $intersections1 = `getAttr ($intersectNode + ".parameter1")`;
- int $numIparms = size($intersections1);
- if( $numIparms == 0 ) {
- delete $intersectNode;
- $intersectNode = "";
- } else {
- $intersections2 = `getAttr ($intersectNode + ".parameter2")`;
- }
- return $intersectNode;
- }
-
- /////////////////////////////////////////////////////////////////////
- // Description:
- // Takes a list of curves and intersects with a specified number
- // of other curves in the list.
- //
- global proc string[] findAllIntersections(
- string $crvs[], int $numCrvsToIntersect,
- int $useDir, float $dirX, float $dirY, float $dirZ,
- float $tolerance,
- int $sorted,
- int $history, string $intersectNodes[] )
- {
- int $i;
- int $j;
- int $numCrvs = size($crvs) - 1;
- string $parms[];
- for( $i = 0; $i < $numCrvs; $i ++ ) {
- for( $j = 0; $j < $numCrvsToIntersect; $j ++ ) {
-
- if( ($numCrvs-$j) > $i ) {
- int $tmp = $numCrvs-$j;
- // intersect $crvs[$i] with $crvs[$numCrvs-$j]
- float $intsx1[];
- float $intsx2[];
- string $intsx = createCrvCrvIntersect(
- $crvs[$i], $crvs[$numCrvs-$j],
- $useDir, $dirX, $dirY, $dirZ, $tolerance,
- $intsx1, $intsx2 );
- int $numIntsx = size($intsx1);
- if( $numIntsx > 0 ) {
- // add the parameter into ordered list for $crvs[$i]
- // and $crvs[$numCrvs-$j]
- for( $p = 0; $p < $numIntsx; $p ++ ) {
- $parms[$i] = $parms[$i] + " " + $intsx1[$p];
- $parms[$numCrvs-$j] = $parms[$numCrvs-$j] + " " + $intsx2[$p];
- if( $history == 1 ) {
- $intersectNodes[$i] = $intersectNodes[$i] +
- $intsx + ".p1["+$p+"] ";
- $intersectNodes[$numCrvs-$j] =
- $intersectNodes[$numCrvs-$j] + $intsx + ".p2["+$p+"] ";
- }
- }
- }
- if( $history == 0 && (size($intsx1) > 0) ) {
- delete $intsx;
- }
- clear( $intsx1 );
- clear( $intsx2 );
- }
- }
- }
-
- // Go through the $parms list and sort each one into ascending order
- //
- if( $sorted == 1 ) {
- int $numTokens;
- float $floatParms[];
- float $sortedParms[];
- string $tokens[];
- string $parmsNew;
- for( $i = 0; $i <= $numCrvs; $i ++ ) {
- $numTokens = 0;
- if( size($parms[$i]) > 0 ) {
- $numTokens = `tokenize $parms[$i] " " $tokens`;
- for( $j = 0; $j < $numTokens; $j ++ ) {
- if( size( $tokens[$j]) > 0 ) {
- $floatParms[size($floatParms)] = $tokens[$j];
- }
- }
- }
- $sortedParms = `sort $floatParms`;
-
- $parmsNew = "";
- for( $j = 0; $j < $numTokens; $j ++ ) {
- $parmsNew += " ";
- $parmsNew += $sortedParms[$j];
- }
- $parms[$i] = $parmsNew;
- clear( $floatParms );
- clear( $sortedParms );
- }
- }
- return $parms;
- }
-